home *** CD-ROM | disk | FTP | other *** search
- //
- // $VER: SimpleMenu.c 2.0 (22.8.97)
- //
- // Popup Menu example program
- //
- // ©1996-1997 Henrik Isaksson
- // All Rights Reserved.
- //
- // Run and click the mouse in the window!
- //
-
- #include <intuition/intuition.h>
-
- #include <clib/intuition_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/alib_protos.h>
-
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #include <libraries/pm.h>
- #include <proto/pm.h>
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct PopupMenuBase *PopupMenuBase;
-
- struct Window *w; // This window is only needed to find out when and where the menu should appear.
- // The font in this window's rastport will be used for the menu.
-
- void main()
- {
- BOOL r=TRUE;
- struct IntuiMessage *im,imsg;
- struct PopupMenu *p;
-
- PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION); // Open the library
- if(PopupMenuBase) {
- IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase; // We let popupmenu.library open the libraries we need
- GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase; // They remain valid until the library is closed!
-
- p=PMMenu("Trashcan"),
- PMItem("Open"), PMEnd,
- PMItem("Submenu"), PM_Sub, PM_MakeMenu(
- PMItem("Testing..."), PMEnd,
- PMItem("...gnitseT"), PMEnd,
- PMEnd,
- PMEnd,
- PMBar, PMEnd,
- PMItem("Snapshot"), PMEnd,
- PMItem("UnSnapshot"), PMEnd,
- PMBar, PMEnd,
- PMItem("Leave out"), PMEnd,
- PMItem("Rename..."), PMEnd,
- PMItem("Delete"), PMEnd,
- PMBar, PMEnd,
- PMItem("Empty"), PM_UserData, 5, PMEnd,
- PMItem("Copy to"), PM_Sub, PM_MakeMenu(
- PMItem("RAM:"), PMEnd,
- PMItem("DH0:"), PMEnd,
- PMItem("DH1:"), PMEnd,
- PMItem("DH2:"), PMEnd,
- PMItem("DF0:"), PMEnd,
- PMEnd,
- PMEnd,
- PMItem("Copy to"), PM_Sub, PM_MakeMenu(
- PMItem("RAM:"), PMEnd,
- PMItem("DH0:"), PMEnd,
- PMItem("DH1:"), PMEnd,
- PMItem("DH2:"), PMEnd,
- PMItem("DH3:"), PMEnd,
- PMItem("DH4:"), PMEnd,
- PMItem("DH5:"), PMEnd,
- PMItem("RAD:"), PMEnd,
- PMItem("DF0:"), PMEnd,
- PMItem("DF1:"), PMEnd,
- PMItem("DF2:"), PMEnd,
- PMItem("DF3:"), PMEnd,
- PMItem("PC0:"), PMEnd,
- PMItem("PC1:"), PMEnd,
- PMItem("TAPE:"), PMEnd,
- PMItem("MAC:"), PMEnd,
- PMItem("CD0: :)"), PMEnd,
- PMEnd,
- PMEnd,
- PMItem("Copy to"), PM_Sub, PM_MakeMenu(
- PMItem("RAM:Clipboards/"), PMEnd,
- PMItem("DH0:Storage/DOSDrivers/"), PMEnd,
- PMEnd,
- PMEnd,
- PMItem("Copy to"), PM_Sub, PM_MakeMenu(
- PMItem("RAM:"), PMEnd,
- PMItem("DH0:"), PMEnd,
- PMEnd,
- PMEnd,
- End;
-
- if(p) {
- w=OpenWindowTags(NULL, WA_IDCMP, IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS, // Open a little window
- WA_RMBTrap, TRUE,
- WA_DragBar, TRUE,
- WA_Width, 150,
- WA_Height, 100,
- WA_Left, 150,
- WA_Top, 0,
- WA_Title, "SimpleMenu",
- WA_CloseGadget, TRUE,
- TAG_DONE);
- if(w) {
- while(r) {
- WaitPort(w->UserPort); // Wait for a message
- while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) { // Get the message
- CopyMem(im,&imsg,sizeof(struct IntuiMessage)); // Copy the contents of it
- ReplyMsg((struct Message *)im); // Reply the message
-
- switch(imsg.Class) {
- case IDCMP_CLOSEWINDOW: r=FALSE; break;
- case IDCMP_MOUSEBUTTONS: // The user has hit a mousebutton - time to open the menu!
- r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
- PM_Menu, p,
- PM_Code, imsg.Code, // Must always be there!
- TAG_DONE))-5);
- break;
- }
- }
- }
- CloseWindow(w);
- } else printf("Window error!\n");
- PM_FreePopupMenu(p);
- } else printf("Menu error!\n");
- CloseLibrary((struct Library *)PopupMenuBase);
- }
- }
-